//-----	Main.c							---------//
//-----	Authur: Chris Chester					---------//
//-----	Date: 29/07/2011					---------//
//-----	Capacitive Sensing on PIC16 chip with a capacitive mat.	---------//


#include <htc.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "functions.h"


__CONFIG(FOSC_INTOSC & WDTE_OFF);

void interrupt ISR();

long time;

/*Main function*/
/*==================================================================================================================================*/	
void main(void){
	
	initialise();
	
	while(1)
	{
		continue;
	}	
}
/*==================================================================================================================================*/	



/* Interupt for Pressure Pad*/
/*==================================================================================================================================*/
void interrupt ISR()
{
	//If timer0 overflow
	//The overflow flag should stop timer1 from counting as it will change the gate bit.
	if(TMR0IE && TMR0IF) // If timer interupt is enabled and flaged
	{
		
			time = TMR1;
		
			if( ball_detect(time)) // Checks to see if the capacitance has increased
			{
				RA7 = 1;		// Turns on LED
				_delay(100000); 	// Waits one seconds
			}
			else
			{
				RA7 = 0;		// Turns off LED
			}
		
			reset_timers();		

	}
}
/*==================================================================================================================================*/


